// 当前文件说明，请参考官方文档：https://cli.vuejs.org/zh/config/
const path = require('path')
const resolve = dir => path.join(__dirname, dir)

// 通过generate-asset-webpack-plugin将自定义配置挂载到Vue原型上：https://www.cnblogs.com/matd/p/11412428.html
function getServerConfig (compilation) {
    const serverConfig = {
        // 系统首页
        serverUrl: "http://192.168.2.42:9090/learn",
        // 语言
        language: "zh-tw"
    }
    return JSON.stringify(serverConfig)
}

/**
 * @type {import('@vue/cli-service').ProjectOptions}
 */
module.exports = {
    // 选项...
    publicPath: '/learn/', //发布项目名
    // 配合 webpack > 链式操作：https://blog.csdn.net/qq_41337100/article/details/119637636
    chainWebpack: config => {
        config.resolve.alias
            .set('node_modules', resolve('node_modules'))
            .set('@', resolve('src'));
        // 通过generate-asset-webpack-plugin将自定义配置挂载到Vue原型上：https://www.cnblogs.com/matd/p/11412428.html
        config.plugin('GenerateAssetPlugin').use('generate-asset-webpack-plugin', [
            {
                filename: 'serverconfig.json',
                fn: (compilation, cb) => {
                    cb(null, getServerConfig(compilation));
                },
                extraFiles: []
            }
        ])
    }

}